package com.learn.educommentboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.learn.eduapi.entity.comment.CourseComment;
import com.learn.eduapi.entity.comment.CourseCommentFavoriteRecord;
import com.learn.eduapi.entity.course.Course;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Repository
@Mapper
public interface CourseCommentDao  extends BaseMapper<CourseComment> {
    @Select("select * from course_comment_favorite_record where user_id = #{userId} and comment_id =#{commentId}" )
    CourseCommentFavoriteRecord  selectByCourseCommentFavoriteRecordId(@Param("userId")Integer userId,@Param("commentId")Integer commentId);

    List<CourseComment> selectgetAllComment(@Param("userId")Integer userId,@Param("id") int id, @Param("pageNum") int pageNum, @Param("pageSize") int pageSize);

    List<CourseComment> getAdminCommentRecord(@Param("find") String  find,@Param("page") int page, @Param("size") int size);


    @Insert("insert into course_comment(section_id,lesson_id,parent_id,user_name,course_id,comment,user_id,last_operator,create_time,update_time) values(0,0,0,#{userName},#{courseId},#{comment},#{userId},#{userId},#{createTime},#{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void addComment(CourseComment comment);

    @Insert("insert into course_comment_favorite_record(user_id,comment_id,is_del,create_time,update_time) values(#{userId},#{commentId},1,#{createTime},#{updateTime})")
    void addCommentFavorite(CourseCommentFavoriteRecord courseCommentFavoriteRecord);

    //第一次添加点赞
    @Insert("insert into course_comment_favorite_record(user_id,comment_id,is_del,create_time,update_time) values(#{userId},#{commentId},0,#{createTime},#{updateTime})")
    void OneaddCommentFavorite(CourseCommentFavoriteRecord courseCommentFavoriteRecord);

    @Update("update course_comment_favorite_record set is_del = 1,update_time = #{updateTime} where user_id = #{userId} and comment_id = #{commentId}")
    void updateComment(String updateTime,Integer commentId, Integer userId);

    @Update("update course_comment_favorite_record set is_del = 0,update_time = #{updateTime} where user_id = #{userId} and comment_id = #{commentId}")
    int updateCommentSave(String updateTime,Integer commentId, Integer userId);

    @Select("select like_count from course_comment where id = #{commentId}")
    Integer selectLikeCount(Integer commentId);

    @Update("update course_comment set like_count = #{i} where id = #{commentId}")
    void updateLikeCount(Integer i,Integer commentId);

    @Delete("delete from course_comment where id = #{commentId}")
    int delComment(Integer commentId);

    @Delete("delete from course_comment_favorite_record where comment_id = #{commentId}")
    int delCommentFavorite(Integer commentId);

    @Delete("delete from course_comment_favorite_record where id = #{id}")
    int delAmdinCommentFavorite(Integer id);

    List<CourseComment> getCommentList(@Param("find") String find, @Param("page")Integer page, @Param("size")Integer size);
    @Select("select * from course_comment_favorite_record where comment_id = #{Id}")
    List<CourseCommentFavoriteRecord> getCrouseRavoritesUserList(@Param("Id") Integer Id);
}
